package com.koron.system.configSettings.post.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Assert;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.koron.bean.query.PageQuery;
import com.koron.bean.system.post.po.PostPo;
import com.koron.bean.system.post.po.PostUserPo;
import com.koron.system.configSettings.post.mapper.PostMapper;
import com.koron.system.configSettings.post.mapper.PostUserMapper;
import com.koron.system.configSettings.post.service.PostService;
import org.koron.ebs.mybatis.TaskAnnotation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (Post)表服务实现类
 *
 * @author zhouj
 * @since 2022-01-10 09:24:27
 */
@Service("postService")
public class PostServiceImpl implements PostService {

    @Autowired
    PostMapper mapper;

    @Autowired
    PostUserMapper postusermapper;

    @Override
    @TaskAnnotation("insertOrUpdate")
    public int insertOrUpdate(PostPo post) {

        return mapper.insertOrUpdate(post);
    }

    @Override
    @TaskAnnotation("insertOrUpdateBatch")
    public int insertOrUpdateBatch(List<PostPo> postList) {

        return mapper.insertOrUpdateBatch(postList);
    }

    @Override
    @TaskAnnotation("insert")
    public int insert(PostPo post) {

        return mapper.insert(post);
    }

    @Override
    @TaskAnnotation("insertBatch")
    public int insertBatch(List<PostPo> postList) {

        return mapper.insertBatch(postList);
    }

    @Override
    @TaskAnnotation("update")
    public int update(PostPo post) {
        return mapper.update(post);
    }

    @Override
    @TaskAnnotation("deleteById")
    public int deleteById(String id) {
        List<PostUserPo> postUserPos = postusermapper.queryByPostId(id);
        Assert.isFalse(CollUtil.isNotEmpty(postUserPos), "岗位下含有人员，不允许删除");
        return mapper.deleteById(id);
    }

    @Override
    @TaskAnnotation("queryById")
    public PostPo queryById(String id) {

        return mapper.queryById(id);
    }

    @Override
    @TaskAnnotation("queryList")
    public List<PostPo> queryList(PostPo post) {

        List<PostPo> list = mapper.queryList(post);

        return list;
    }

    @Override
    @TaskAnnotation("queryPageList")
    public PageInfo queryPageList(PostPo post, PageQuery pageQuery) {

        PageHelper.startPage(pageQuery.getPage(), pageQuery.getPageSize(), pageQuery.getOrderBy());

        List<PostPo> list = mapper.queryList(post);

        return new PageInfo(list);
    }

}
